package com.grsu.TransportSystem.services;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.grsu.TransportSystem.dao.IPersonDAO;
import com.grsu.TransportSystem.domain.Person;

@Service
public class PersonService {
	
	@Autowired
	private IPersonDAO personDao;
	
	@Transactional
	public Person getUserByLoginPassword(String login,String password) 
	{
		return personDao.findByLoginandPassword(login, password);
	}
	
	@Transactional
	public List<Person> getPerson(Person example)
	{
		return personDao.read(example);
	}
	
	@Transactional
	public List<Person> getPersonByRole(String role)
	{
		return personDao.findByRole(role);
	}
	
	@Transactional
	public Person getPersonById(String id)
	{
		Person example = new Person();
		example.setId(id);
		List<Person> list = personDao.read(example);
		if(list!= null && list.size()>0)
			return list.get(0);
		return null;
	}
	
	@Transactional
	public Person findByLogin(String login)
	{
		return personDao.findByLogin(login);
	}
	

}
